package com.tjbklx1.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class JedisUtil {

	public static Jedis getJedis() {
		Jedis redis = null;
		try {
			JedisPool pool = new JedisPool("localhost", 6379);
			redis = pool.getResource();
			return redis;

		} catch (Exception e) {
			e.printStackTrace();
			if (redis != null) {
				redis.close();
			}
			e.printStackTrace();
		}
		// finally {
		// if (redis != null) {
		// redis.close();
		// }
		// }
		return redis;
	}

	public static Jedis getJedisWithDB() {
		Jedis redis = null;
		try {
			redis = new Jedis("localhost");
			redis.select(0);
			return redis;

		} catch (Exception e) {
			e.printStackTrace();
			if (redis != null) {
				redis.close();
			}
			e.printStackTrace();
		}
		return redis;
	}

}
